package com.example.simple;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class HelloScheduler2 {

    public static void main(String[] args) throws SchedulerException, InterruptedException {

        // 定义一个jobDetail
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class)
                .withIdentity("helloJob").build();

        // 定义一个Trigger
        CronTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("helloTrigger2")
                .withSchedule(
                        CronScheduleBuilder.cronSchedule("0/1 * * * * ?")
                ).build();

        // 定义一个定时器容器
        StdSchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();
        scheduler.start();

        // 容器运行job
        scheduler.scheduleJob(jobDetail, trigger);

        Thread.sleep(3000);

        scheduler.pauseJob(new JobKey("helloJob"));

        Thread.sleep(3000);
        scheduler.resumeJob(new JobKey("helloJob"));
    }

}
